package main

import (
	"fmt"
	"os"
	"io"
)

func copyFile(src string, dst string) (result string) {
	// 先打开文件
	srcFile, err1 := os.Open(src)
	defer srcFile.Close()
	dstFile, err2 := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, os.ModePerm)
	defer dstFile.Close()
	if err1 != nil {
		return "打开源文件失败"
	}
	if err2 != nil {
		return "打开目标文件失败"
	}
	var tempSlice = make([]byte, 1024)
	for {
		fmt.Println("开始拷贝……")
		n1, err_r := srcFile.Read(tempSlice)
		if (err_r == io.EOF) {
			break
		}
		if (err_r != nil) {
			return "读取源文件失败"
		}
		_, err_w := dstFile.Write(tempSlice[:n1])
		if (err_w != nil) {
			return "写入目标文件失败"
		}
	}
	return "复制文件成功！"
}

func main() {
	fmt.Println(copyFile("D:/dev/golang/dadi/test.txt", "D:/dev/golang/dadi/test1.txt"))
}